let UploadToken = function({ $el, callback }) {
    this.$el = $el;
    this.callback = callback;
    this.init()
}

UploadToken.prototype = {
    constructor: UploadToken,
    init() {
        this.upload()
    },
    upload() {
        this.$el.on('change', async function() {
            let token = await getToken();
            this.sendPic(token.msg)
        }.bind(this))
    },
    sendPic(token) {
        let that = this;
        let file = this.$el[0].files[0];
        let key = Date.now();
        let config = {
            useCdnDomain: true,
            region: qiniu.region.z1,
        };
        let putExtra = {}
        qiniu
            .upload(file, key, token, putExtra, config)
            .subscribe({
                next(res) {
                    // console.log(res.total.percent);
                },
                complete(res) {
                    that.callback(res.url);
                }
            })
    }
}